package com.aimeizi.clz.aimeizi.moudle.splash;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aimeizi.clz.aimeizi.R;
import com.aimeizi.clz.aimeizi.config.ConstantsImageUrl;
import com.aimeizi.clz.aimeizi.moudle.home.HomeActivity;
import com.bumptech.glide.Glide;
import com.clz.appdesign.appdependence.base.BaseActivity;

import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author clz
 * @desc 首屏页
 */
public class SplashActivity extends BaseActivity {


    @BindView(R.id.iv_ad)
    ImageView mIvAd;
    @BindView(R.id.tv_jump)
    TextView mTvJump;
    @BindView(R.id.iv_default)
    ImageView mIvDefault;
    private boolean isIn;
    private Handler mHandler = new Handler();

    @Override
    public void initToolbar() {
        setSteepStatusBar(true);
        ButterKnife.bind(this);
    }

    @Override
    public void beforeInit() {
        super.beforeInit();
        setAllowFullScreen(true);
    }

    @Override
    public void initView() {
        int i = new Random().nextInt(ConstantsImageUrl.TRANSITION_URLS.length);
        mIvDefault.setImageResource(R.drawable.img_transition_default);

        Glide.with(this).load(ConstantsImageUrl.TRANSITION_URLS[i])
                .placeholder(R.drawable.img_transition_default)
                .error(R.drawable.img_transition_default)
                .into(mIvAd);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                mIvDefault.setVisibility(View.GONE);
                mHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        toHomeActivity();
                    }
                }, 3000);
            }
        }, 2000);

    }

    private void toHomeActivity() {
        if (isIn) {
            return;
        }
        Intent intent = new Intent(this, HomeActivity.class);
        startActivity(intent);
        overridePendingTransition(R.anim.scrren_in, R.anim.scrren_out);
        finish();
        isIn = true;
    }

    @Override
    public void initData() {

    }

    @Override
    public void doBusiness(Context mContext) {

    }

    @Override
    public int layoutResID() {
        return R.layout.activity_splash;
    }


    @OnClick(R.id.tv_jump)
    public void onViewClicked() {
        toHomeActivity();
        mHandler.removeCallbacksAndMessages(null);
    }
}
